/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_cics_header_unpack.c                             */
/*  NOTE      =                                                    */
/*  DATE      = 2016/02/19 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"

#include <cics/config.h>
#include <cics/cics_core.h>
#include <cics/cics_header.h>
#include <cics/cics_comm.h>
#include <apmtest_comm.h>

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    char *p_bin = (char *) "47617465007010000000000500000000000000000000000442415345000000001600027a680002434e0000000000000000000000000000";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    Cics_header st_cics_header;
    memset(&st_cics_header, 0x00, sizeof(st_cics_header));

    CU_ASSERT_EQUAL(cics_header_unpack(arr_payload, strlen(p_bin) / 2, &st_cics_header), FR_SUCC);
    CU_ASSERT_EQUAL(st_cics_header.ui_flow_version, APM_CICS_GATEWAY_FLOW_V710);
    CU_ASSERT_EQUAL(st_cics_header.ui_flow_type, 5);
    CU_ASSERT_EQUAL(st_cics_header.ui_msg_id, 0);
    CU_ASSERT_STRING_EQUAL(st_cics_header.arr_req_type, "BASE");
    CU_ASSERT_EQUAL(st_cics_header.ui_header_len, 33);
    CU_ASSERT_EQUAL(st_cics_header.ui_data_which_follows, 22);
}

int add_suite_cics_header_unpack(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" cics_header_unpack()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
